<template>
  <div class="org-page">
    <main>
      <div class="header">
        <p class="title">参与的项目</p>
        <div class="search-container">
          <div class="search-input">
            <el-input placeholder="项目名称/项目简称" v-model="orgCondition"></el-input>
            <el-button class="search-btn" type="primary" @click="handleSearch">
              <i class="el-icon-search"></i>
            </el-button>
            <el-button type="primary" @click="handleRefresh">
              <i class="el-icon-refresh"></i>
            </el-button>
          </div>
          <div class="btns">
            <el-button @click="$router.back()">返回</el-button>
          </div>
        </div>
      </div>
      <div class="table-container">
        <el-table
          v-loading="tableLoading"
          :data="tableData"
          row-key="id">
          <el-table-column label="序号" type="index" width="80"></el-table-column>
          <el-table-column prop="projectName" label="项目名称"></el-table-column>
          <el-table-column prop="projectAbbreviation" label="项目简称"></el-table-column>
          <el-table-column prop="attrName" label="项目属性"></el-table-column>
          <el-table-column prop="remark" label="备注" width="300" show-overflow-tooltip></el-table-column>
          <el-table-column prop="action" label="操作" width="120">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="$router.push('/project-detail?id=' + scope.row.projectId)">
                详情
              </el-button>
            </template>
          </el-table-column>
          <div class="empty-content" slot="empty">
            <i class="iconfont iconwushuju"></i>
            <p>暂无数据</p>
          </div>
        </el-table>
        <el-pagination
          v-if="total > 10"
          :page-size="pageSize"
          :current-page="pageNo"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </main>
  </div>
</template>

<script>

export default {
  data() {
    return {
      orgCondition: '',
      hasSearch: false,
      pageNo: 1,
      pageSize: 10,
      total: 0,
      orgId: '',
      tableData: [],
      tableLoading: false,
    };
  },
  watch: {
    visible(val) {
      if (!val) {
        this.loading = false;
      }
    },
  },
  created() {
    this.orgId = this.$route.query.id || '';
    this.getTableData();
  },
  methods: {
    /**
     * 获取机构树
     */
    async getTableData() {
      if (!this.orgId) return;
      this.tableLoading = true;
      const { success, data: {
        data
      }} = await this.$Model.getMulcontractors({
        pageSize: this.pageSize,
        pageNum: this.pageNo,
        orgCondition: this.hasSearch ? this.orgCondition : '',
        orgId: this.orgId
      });
      this.tableLoading = false;
      if (success) {
        this.tableData = data.list || [];
      }
    },
    clear() {
      this.pageNo = 1;
      this.pageSize = 10;
      this.total = 0;
    },
    handleSearch() {
      this.hasSearch = true;
      this.clear();
      this.getTableData();
    },
    handleRefresh() {
      this.hasSearch = false;
      this.clear();
      this.getTableData();
    },
    /**
     * pageSize 改变时会触发
     * @param pageSize 每页条数
     */
    handleSizeChange(pageSize) {
      this.pageNo = 1;
      this.pageSize = pageSize;
      this.getTableData();
    },
    /**
     * currentPage 改变时会触发
     * @param pageNo 当前页
     */
    handleCurrentChange(pageNo) {
      this.pageNo = pageNo;
      this.getTableData();
    },
  }
};
</script>

<style scoped lang="scss">
  @import "../../assets/styles/table";
  @import "../../assets/styles/dialog";

  .org-page {
    width: 100%;
    height: 100%;
    padding: 20px 30px;
    background-color: $baseBg;
    main {
      width: 100%;
      height: 100%;
      padding: 20px;
      background-color: $mainBg;
      .header {
        width: 100%;
        height: 100px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        margin-bottom: 20px;
        .title {
          font-size: 20px;
        }
        .search-container {
          display: flex;
          justify-content: space-between;
          align-items: center;
          .search-input {
            display: flex;
            .tabs {
              display: flex;
              margin-right: 20px;
              box-shadow: 0 0 3px 0 $mainBg;
              li {
                width: 120px;
                background: #fff;
                color: rgba(0, 0, 0, .8);
                display: flex;
                justify-content: center;
                align-items: center;
                cursor: pointer;
                transition: all .2s;
                &.active, &:hover {
                  background: $linearG;
                  color: #fff;
                }
                &:nth-child(1) {
                  border-radius: 5px 0 0 5px;
                }
                &:nth-last-child(1) {
                  border-radius: 0 5px 5px 0;
                }
              }
            }
            .el-input {
              width: 260px;
              margin-right: 20px;
            }
          }
        }
        .btns {
          .upload-file {
            position: relative;
            cursor: pointer;
            .file {
              position: absolute;
              width: 100%;
              height: 100%;
              top: 0;
              left: 0;
              right: 0;
              bottom: 0;
              opacity: 0;
              cursor: pointer;
            }
          }
        }
      }
      .table-container {
        width: 100%;
        height: calc(100% - 100px);
        /deep/ .el-table {
          height: calc(100% - 50px);
          .el-table__body-wrapper {
            height: calc(100% - 40px);
            overflow-y: auto;
            .btn {
              color: $mainColor;
              cursor: pointer;
              &:hover {
                text-decoration: underline;
              }
            }
          }
        }
      }
    }
  }
</style>
